<?php

use yii\helpers\Html;
use common\modules\attachment\widgets\SingleWidget;
use kartik\select2\Select2;
use common\models\Depot;
use yii\helpers\ArrayHelper;
use kartik\form\ActiveForm;
use kartik\datecontrol\DateControl;
use common\models\GoodsCategory;
use common\models\DepotPosition;

/* @var $this yii\web\View */
/* @var $model common\models\Goods */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="box box-primary">
    <div class="box-body">
    <?php $form =ActiveForm::begin(); ?>

     <?= $form->field($model, 'depot_id')->widget(Select2::className(),[
        'options' => ['placeholder' => '请选择仓库'],
        'data'=>ArrayHelper::map(Depot::find()->all(),'id', 'name'),
         'pluginEvents' =>[
             "select2:select" => "function() { 
              var id=$(this).val();
              $.get('/goods/get-position?id='+id,function(res){
              console.log(22);
              $('#position_id').html(res);
              }); 
         }",
         ]
    ])->label('仓库') ?>
        <?= $form->field($model, 'position_id')->widget(Select2::className(),[
        'options' => ['placeholder' => '请选择仓位','id'=>'position_id'],
        'data'=>ArrayHelper::map(DepotPosition::find()->all(),'id', 'sn')
    ])?> 
    <?= $form->field($model, 'created_at')->widget(DateControl::className(), [
    'type'=>DateControl::FORMAT_DATE,
    'ajaxConversion'=>false,
    'autoWidget'=>true,
    'widgetOptions' => [
        'options' => ['placeholder' => 'Select operating time ...'],
        'pluginOptions' => [
            'autoclose' => true,
            'todayHighlight' => true
        ]
    ]])?>
    <?= $form->field($model, 'category_id')->widget(Select2::className(),[
        'options' => ['placeholder' => '请选择分类'],
        'data'=>ArrayHelper::map(GoodsCategory::find()->all(),'id', 'category_name')
    ]) ?> 
      
    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'format')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'num')->textInput() ?>

    <?= $form->field($model, 'unit')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'price')->textInput(['maxlength' => true]) ?>

  


    <?= $form->field($model, 'attachment')->widget(SingleWidget::className(),['onlyUrl' => true]) ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success btn-flat' : 'btn btn-primary btn-flat']) ?>
    </div>

    <?php ActiveForm::end(); ?>
    </div>
</div>
